

//
//  CommonLeftViewController.m
//  广告页
//
//  Created by YYY on 2017/2/20.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

#import "CommonLeftViewController.h"

#import "AppDelegate.h"

@interface CommonLeftViewController ()

@end

@implementation CommonLeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *listBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [listBtn setImage:[UIImage imageNamed:@"list"] forState:UIControlStateNormal];
    [listBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    listBtn.frame = CGRectMake(0, 0, 50, 30);
    [listBtn addTarget:self action:@selector(listAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:listBtn];
    // Do any additional setup after loading the view.
}

-(void)listAction:(UIButton *)listBtn
{
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    if (appDelegate.LeftSlideVC.closed)
    {
        [appDelegate.LeftSlideVC openLeftView];
    }
    else
    {
        [appDelegate.LeftSlideVC closeLeftView];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [tempAppDelegate.LeftSlideVC setPanEnabled:NO];
    
    // 开启返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [tempAppDelegate.LeftSlideVC setPanEnabled:YES];
    
    if (self.navigationController.viewControllers.count ==1)
    {
        // 禁用返回手势
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
        {
            self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
